本文整理汇总了C#中ITypeDefinition.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDefinition.ToString方法的具体用法?C# ITypeDefinition.ToString怎么用?C# ITypeDefinition.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDefinition
的用法示例。
在下文中一共展示了ITypeDefinition.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _Visit
protected virtual JsNode _Visit(ITypeDefinition ce)
{
if (CompilerConfiguration.Current.EnableLogging)
{
Log.Debug("JsTypeImporter: Visit Type: " + ce.ToString());
}
JsNode node;
if (ce.Kind == TypeKind.Class)
{
node = _VisitClass(ce);
}
else if (ce.Kind == TypeKind.Interface)
{
node = _VisitInterface(ce);
}
else if (ce.Kind == TypeKind.Delegate)
{
node = _VisitDelegate(ce);
}
else if (ce.Kind == TypeKind.Struct)
{
node = _VisitStruct(ce);
}
else if (ce.Kind == TypeKind.Enum)
{
node = _VisitEnum(ce);
}
else
{
throw new NotImplementedException();
}
return node;
}
示例2: Visit
/// <summary>
/// Visits only classes: throws an exception for all other type definitions.
/// </summary>
///
public override void Visit(ITypeDefinition typeDefinition) {
if (typeDefinition.IsClass) {
base.Visit(typeDefinition);
} else {
Console.WriteLine("Non-Class {0} was found", typeDefinition);
throw new NotImplementedException(String.Format("Non-Class Type {0} is not yet supported.", typeDefinition.ToString()));
}
}
示例3: CompareTo
public int CompareTo(ITypeDefinition other)
{
return other == null
? -1
: string.Compare(ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase);
}
示例4: GetTypeSignature
private static string GetTypeSignature(ITypeDefinition pDefinition)
{
return pDefinition.ToString();
}
示例5: CreateType
private static HLType CreateType(ITypeDefinition pDefinition)
{
HLType type = new HLType();
type.Definition = pDefinition;
type.Name = pDefinition.ToString(); // TODO: Don't really like this, should use TypeHelper perhaps?
type.Signature = HLDomain.GetTypeSignature(pDefinition);
sTypes[type.Signature] = type;
ITypeReference referenceBase = pDefinition.BaseClasses.FirstOrDefault();
if (referenceBase != null)
{
type.BaseType = GetOrCreateType(referenceBase);
type.BaseType.MemberFields.ForEach(f => type.Fields.Add(f));
}
foreach (IFieldDefinition fieldDefinition in pDefinition.Fields.OrderBy(d => d.SequenceNumber))
CreateField(type, fieldDefinition);
IMethodDefinition definitionStaticConstructor = pDefinition.Methods.FirstOrDefault(d => d.IsStaticConstructor);
if (definitionStaticConstructor != null) type.StaticConstructor = GetOrCreateMethod(definitionStaticConstructor);
return type;
}
示例6: getListOfAllImplementedInterfaces
// gets recursivly a list of all interfaces that are used by this interface
private void getListOfAllImplementedInterfaces(ITypeDefinition classInterface) {
// check if the interface has other interfaces that have to be implemented
// if not => just add this interface
if (classInterface.Interfaces == null) {
if (this.interfacesList.Contains(classInterface)) {
this.logger.writeLine("Interface \"" + classInterface.ToString() + "\" already in list");
return;
}
this.logger.writeLine("Add interface to list: " + classInterface.ToString());
this.interfacesList.Add(classInterface);
}
// else => add all interfaces that should be implemented to the list
else {
if (!this.interfacesList.Contains(classInterface)) {
this.logger.writeLine("Add interface to list: " + classInterface.ToString());
this.interfacesList.Add(classInterface);
}
else {
this.logger.writeLine("Interface \"" + classInterface.ToString() + "\" already in list");
}
for (int i = 0; i < classInterface.Interfaces.Count(); i++) {
// only add interfaces if it implements ITypeDefinition
if (classInterface.Interfaces.ElementAt(i) as ITypeDefinition != null) {
ITypeDefinition implementedInterface = (ITypeDefinition)classInterface.Interfaces.ElementAt(i);
if (this.interfacesList.Contains(implementedInterface)) {
this.logger.writeLine("Interface \"" + implementedInterface.ToString() + "\" already in list");
continue;
}
this.logger.writeLine("Add interface to list: " + implementedInterface.ToString());
this.interfacesList.Add(implementedInterface);
// recursivly add all interfaces that extends this one to the interface list
this.logger.writeLine("Resolve inheritance of interface: " + implementedInterface.ToString());
getListOfAllImplementedInterfaces(implementedInterface);
continue;
}
// check if the ResolvedType implements the ITypeDefinition
else if (classInterface.Interfaces.ElementAt(i).ResolvedType as ITypeDefinition != null) {
ITypeDefinition implementedInterface = (ITypeDefinition)classInterface.Interfaces.ElementAt(i).ResolvedType;
if (this.interfacesList.Contains(implementedInterface)) {
this.logger.writeLine("Interface \"" + implementedInterface.ToString() + "\" already in list");
continue;
}
this.logger.writeLine("Add interface to list: " + implementedInterface.ToString());
this.interfacesList.Add(implementedInterface);
// recursivly add all interfaces that extends this one to the interface list
this.logger.writeLine("Resolve inheritance of interface: " + implementedInterface.ToString());
getListOfAllImplementedInterfaces(implementedInterface);
continue;
}
else {
throw new ArgumentException("Do not know how to handle interface.");
}
}
}
}
示例7: addInterface
// adds the given interface to the given class
public void addInterface(NamespaceTypeDefinition addTargetClass, ITypeDefinition interfaceToAdd) {
// add interface to target class
if (addTargetClass.Interfaces != null) {
// check if interface is already implemented by class
if (addTargetClass.Interfaces.Contains(interfaceToAdd)) {
this.logger.writeLine("Class \"" + addTargetClass.ToString() + "\" already implements interface \"" + interfaceToAdd.ToString() + "\"");
return;
}
else {
this.logger.writeLine("Add interface \"" + interfaceToAdd.ToString() + "\" to class \"" + addTargetClass.ToString() + "\"");
addTargetClass.Interfaces.Add(interfaceToAdd);
}
}
else {
List<ITypeReference> interfaceList = new List<ITypeReference>();
interfaceList.Add(interfaceToAdd);
addTargetClass.Interfaces = interfaceList;
}
// copy all attributes from the interface to the target class
if (interfaceToAdd.Fields != null) {
foreach (FieldDefinition field in interfaceToAdd.Fields) {
FieldDefinition copy = new FieldDefinition();
this.helperClass.copyField(copy, field);
copy.ContainingTypeDefinition = addTargetClass;
// set intern factory of the copied field to the one of the class
// (without it, the generated binary file will have strange results like use only the same field)
copy.InternFactory = addTargetClass.InternFactory;
addTargetClass.Fields.Add(copy);
}
}
// copy all methods from the interface to the target class
if (interfaceToAdd.Methods != null) {
foreach (IMethodDefinition method in interfaceToAdd.Methods) {
// search through all methods in the target class
// to see if this method was already added
bool foundMethod = false;
foreach (IMethodDefinition tempMethod in addTargetClass.Methods) {
// skip constructors
if (tempMethod.IsConstructor) {
continue;
}
// check if the number of parameters are the same
if (tempMethod.ParameterCount == method.ParameterCount) {
// check if the parameters have the same type in the same order
bool parameterCorrect = true;
for (int i = 0; i < method.ParameterCount; i++) {
if (method.Parameters.ElementAt(i).Type != tempMethod.Parameters.ElementAt(i).Type) {
parameterCorrect = false;
break;
}
}
// check if the return type is the same
bool returnTypeCorrect = false;
if (method.Type.Equals(tempMethod.Type)) {
returnTypeCorrect = true;
}
// check if both methods are static
// (c# compiler does not allow static + non-static function with
// same signature in same class, but CIL does)
bool bothStatic = false;
if (method.IsStatic == tempMethod.IsStatic) {
bothStatic = true;
}
// if the parameters and return type are correct => check the name
if (parameterCorrect && returnTypeCorrect && bothStatic) {
if (method.Name.Equals(tempMethod.Name)) {
// if name is the same => method already added
foundMethod = true;
break;
}
}
}
}
// skip if method was already added
if (foundMethod) {
this.logger.writeLine("Method \"" + method.Name.ToString() + "\" already exists");
continue;
}
this.logger.writeLine("Add method: " + method.Name.ToString());
// copy method
MethodDefinition copy = new MethodDefinition();
this.helperClass.copyMethod(copy, method);
//.........这里部分代码省略.........
示例8: PrintTypeDefinitionName
public virtual void PrintTypeDefinitionName(ITypeDefinition typeDefinition) {
INamespaceTypeDefinition namespaceTypeDefinition = typeDefinition as INamespaceTypeDefinition;
if (namespaceTypeDefinition != null) {
PrintIdentifier(namespaceTypeDefinition.Name);
return;
}
INestedTypeDefinition nestedTypeDefinition = typeDefinition as INestedTypeDefinition;
if (nestedTypeDefinition != null) {
PrintIdentifier(nestedTypeDefinition.Name);
return;
}
INamedEntity namedEntity = typeDefinition as INamedEntity;
if (namedEntity != null) {
PrintIdentifier(namedEntity.Name);
} else {
sourceEmitterOutput.Write(typeDefinition.ToString());
}
}