예제 #1
0
 private bool IsMethodParameterSame(TypeReference typeReference, XmlMetaModel.ArgumentModel argument)
 {
     if (typeReference.IsGenericParameter)
     {
         return(typeReference.Name == argument.type);
     }
     else if (typeReference.IsGenericInstance)
     {
         GenericInstanceType genericInstanceType = (GenericInstanceType)typeReference;
         int pos = argument.type.IndexOf('^');
         if (pos != -1)
         {
             int count = int.Parse(argument.type.Substring(pos + 1));
             if (genericInstanceType.GenericArguments.Count == count)
             {
                 string name = argument.type;
                 XmlMetaMaker.FixName(ref name);
                 string fullName = genericInstanceType.Namespace + '.' + genericInstanceType.Name;
                 if (fullName == name)
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     else if (typeReference.IsNested)
     {
         return(typeReference.FullName.Replace("/", ".") == argument.type);
     }
     else
     {
         return(typeReference.FullName == argument.type);
     }
 }
예제 #2
0
        private static bool IsAutoPropertyOfDefinitionInternal(PropertyDefinition propDef)
        {
            bool isAutoField = XmlMetaMaker.IsAutoField(propDef);

            if (isAutoField)
            {
                return(true);
            }

            var typeDef = propDef.DeclaringType;

            return(typeDef.Fields.Any(f => !f.IsPublic && f.Name.Contains("<" + propDef.Name + ">")));
        }
예제 #3
0
 private void Method()
 {
     if (model_.Methods != null)
     {
         foreach (var methodModel in model_.Methods)
         {
             var methods = TypeDefinition.Methods.Where(i => IsMethodMatchAll(i, methodModel));
             foreach (MethodDefinition methodDefinition in methods)
             {
                 MethodMetaInfo info = new MethodMetaInfo(methodDefinition, methodModel);
                 XmlMetaMaker.AddMethod(info);
             }
         }
     }
 }
예제 #4
0
 private void Field()
 {
     if (model_.Fields != null)
     {
         foreach (var fieldModel in model_.Fields)
         {
             FieldDefinition fieldDefinition = TypeDefinition.Fields.FirstOrDefault(i => i.Name == fieldModel.name);
             if (fieldDefinition == null)
             {
                 throw new ArgumentException(fieldModel.name + " is not found at " + TypeDefinition.FullName);
             }
             FieldMetaIfo info = new FieldMetaIfo(fieldDefinition, fieldModel);
             XmlMetaMaker.AddField(info);
         }
     }
 }
예제 #5
0
 private void Property()
 {
     if (model_.Propertys != null)
     {
         foreach (var propertyModel in model_.Propertys)
         {
             PropertyDefinition propertyDefinition = TypeDefinition.Properties.FirstOrDefault(i => i.Name == propertyModel.name);
             if (propertyDefinition == null)
             {
                 throw new ArgumentException(propertyModel.name + " is not found at " + TypeDefinition.FullName);
             }
             PropertyMataInfo info = new PropertyMataInfo(propertyDefinition, propertyModel);
             XmlMetaMaker.AddProperty(info);
         }
     }
 }
예제 #6
0
        public static string ToJsName(IType type, IEmitter emitter, bool asDefinition = false, bool excludens = false, ToNameTypeEnum kind = ToNameTypeEnum.None)
        {
            if (NullableType.IsNullable(type))
            {
                return(BridgeTypes.ToJsName(NullableType.GetUnderlyingType(type), emitter));
            }

            if (type.Kind == TypeKind.Delegate)
            {
                return("System.Delegate");
            }

            BridgeType bridgeType = emitter.BridgeTypes.Get(type, true);
            var        name       = excludens ? "" : XmlMetaMaker.GetNamespace(bridgeType != null ? bridgeType.Type.Namespace : type.Namespace);

            var hasTypeDef = bridgeType != null && bridgeType.TypeDefinition != null;

            if (hasTypeDef)
            {
                var typeDef = bridgeType.TypeDefinition;
                if (typeDef.IsNested && !excludens)
                {
                    name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(typeDef);
                }

                name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.ConvertName(typeDef.Name);
            }
            else
            {
                if (type.DeclaringType != null && !excludens)
                {
                    name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(type);

                    if (type.DeclaringType.TypeArguments.Count > 0)
                    {
                        name += "_" + type.TypeArguments.Count;
                    }
                }

                name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.ConvertName(type.Name);
            }


            bool isCustomName = false;

            if (bridgeType != null)
            {
                name = BridgeTypes.AddModule(name, bridgeType, out isCustomName);
            }

            if (kind == ToNameTypeEnum.None)
            {
                int pos = name.LastIndexOf('.');
                if (pos != -1)
                {
                    string prefix = name.Substring(0, pos);
                    if (prefix != "System")
                    {
                        TransformCtx.CurUsingNamespaces.Add(prefix);
                        string newPrefix = prefix.Replace(".", "");
                        if (newPrefix == prefix)
                        {
                            newPrefix = '_' + newPrefix;
                        }
                        name = newPrefix + name.Substring(pos);
                    }
                }
            }

            if (!hasTypeDef && !isCustomName && type.TypeArguments.Count > 0)
            {
                name += "_" + type.TypeArguments.Count;
            }

            if (!asDefinition && type.TypeArguments.Count > 0 && !Helpers.IsIgnoreGeneric(type, emitter))
            {
                StringBuilder sb        = new StringBuilder(name);
                bool          needComma = false;
                sb.Append("(");
                foreach (var typeArg in type.TypeArguments)
                {
                    if (needComma)
                    {
                        sb.Append(", ");
                    }

                    needComma = true;
                    sb.Append(BridgeTypes.ToNameIgnoreEnum(typeArg, emitter, kind));
                }

                sb.Append(")");
                name = sb.ToString();
            }
            else if (type.Kind == TypeKind.Array)
            {
                name += "(" + BridgeTypes.ToNameIgnoreEnum(((ICSharpCode.NRefactory.TypeSystem.ArrayType)type).ElementType, emitter) + ")";
            }

            return(name);
        }
예제 #7
0
        protected virtual List <IProperty> GetPropertyOverloads(List <IProperty> list = null, ITypeDefinition typeDef = null)
        {
            bool isTop = list == null;

            list    = list ?? new List <IProperty>();
            typeDef = typeDef ?? this.TypeDefinition;

            if (typeDef != null)
            {
                bool isFromCode = this.Emitter.BridgeTypes.Get(typeDef).IsFromCode;
                var  properties = typeDef.Properties.Where(p =>
                {
                    if (!isFromCode)
                    {
                        if (p.IsPrivate || p.IsInternal)
                        {
                            return(false);
                        }
                    }

                    if (!this.IncludeInline)
                    {
                        var inline = p.Getter != null ? XmlMetaMaker.GetPropertyInline(p, true) : null;
                        if (!string.IsNullOrWhiteSpace(inline))
                        {
                            return(false);
                        }

                        inline = p.Setter != null ? XmlMetaMaker.GetPropertyInline(p, false) : null;
                        if (!string.IsNullOrWhiteSpace(inline))
                        {
                            return(false);
                        }
                    }

                    bool eq = false;
                    if (p.IsStatic == this.Static)
                    {
                        var getterIgnore = p.Getter != null && this.Emitter.Validator.IsIgnoreType(p.Getter);
                        var setterIgnore = p.Setter != null && this.Emitter.Validator.IsIgnoreType(p.Setter);
                        var getterName   = p.Getter != null ? Helpers.GetPropertyRef(p, this.Emitter, false, true, true) : null;
                        var setterName   = p.Setter != null ? Helpers.GetPropertyRef(p, this.Emitter, true, true, true) : null;
                        if (!getterIgnore && getterName != null && (getterName == this.JsName || getterName == this.AltJsName))
                        {
                            eq = true;
                        }
                        else if (!setterIgnore && setterName != null && (setterName == this.JsName || setterName == this.AltJsName))
                        {
                            eq = true;
                        }
                    }

                    if (eq)
                    {
                        if (p.IsOverride && !this.IsTemplateOverride(p))
                        {
                            return(false);
                        }

                        return(true);
                    }

                    return(false);
                });

                list.AddRange(properties);

                if (this.Inherit)
                {
                    var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class));

                    foreach (var baseTypeDef in baseTypeDefinitions)
                    {
                        var result = this.GetPropertyOverloads(list, baseTypeDef.GetDefinition());
                        list.AddRange(result);
                    }
                }
            }

            return(isTop ? list.Distinct().ToList() : list);
        }